package com.rtline.business.controller;

import com.rtthreadlocal.threadlocalstarter.ThreadLocalUtil;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>ThreadLocalController .
 *
 * <p>change history:
 *
 * <pre>
 * date         defect       person          comments
 * --------------------------------------------------------------------------------
 * 2025/6/2    ********     Tao Ren    create file.
 * </pre>
 *
 * @author Tao Ren
 * @date 2025/6/2 21:04
 */
@RestController
public class ThreadLocalController {
    @GetMapping("/set")
    public String setThreadLocalValue() {
        ThreadLocalUtil.set("user", "John Doe");
        Object value = ThreadLocalUtil.get("user");
        return "Value set" + value;
    }

    @GetMapping("/get")
    public String getThreadLocalValue() {
        Object value = ThreadLocalUtil.get("user");
        return value != null ? value.toString() : "No value set";
    }

    @GetMapping("/clear")
    public String clearThreadLocalValue() {
        ThreadLocalUtil.clear();
        return "ThreadLocal cleared";
    }
}
